<template>
    <div class="shopManage">
        <shop-header></shop-header>
        <div v-show="shopMenu['店铺管理'].length!=0" class="shopManage-item">
            <group-title @click.native="setListType()">
                <img width="20" v-show="shop.shopHeaderState.listType!='1'" class="manager-list" src="~assets/x3/ico/icon-lb.png">
                <img width="20" v-show="shop.shopHeaderState.listType=='1'" class="manager-list" src="~assets/x3/ico/icon-dc.png">
                <div>店铺管理</div>
            </group-title>
            <grid :cols="shopRows">
                <grid-item v-if="isDisplay(menu)" v-for="(menu,index) in shopMenu['店铺管理']" :key="index" @click.native="goMenu(menu)">
                    <img slot="icon" :src="menu.imgUrl">
                    <span slot="label">{{menu.serviceCname}}</span>
                </grid-item>
                <!-- <grid-item @click.native="goUrl(RouteUrl.PRODUCT_MANAGE)">
                    <img slot="icon" src="~assets/x3/shop/product_management3x.png">
                    <span slot="label">产品管理</span>
                </grid-item>
                <grid-item @click.native="goUrl(RouteUrl.PERFORMANCE_STATISTICS)">
                    <img slot="icon" src="~assets/x3/shop/achievement3x.png">
                    <span slot="label">店铺业绩</span>
                </grid-item>
                <grid-item @click.native="goUrl(RouteUrl.SET_SHOP)" v-show="isModifyShopInfo">
                    <img slot="icon" src="~assets/x3/shop/shop_set3x.png">
                    <span slot="label">店铺信息设置</span>
                </grid-item> -->
            </grid>
        </div>
        <div v-show="shopMenu['销售工具'].length!=0" class="shopManage-item shopManage-tool">
            <group-title>
                <img width="20" class="manager-list" src="~assets/x3/ico/tool.png">
                <div>销售工具</div>
            </group-title>
            <grid :cols="shopRows">
                <grid-item v-for="(menu,index) in shopMenu['销售工具']" :key="index" @click.native="goMenu(menu)">
                    <img slot="icon" :src="menu.imgUrl">
                    <span slot="label">{{menu.serviceCname}}</span>
                </grid-item>
                <!-- <grid-item @click.native="goUrl(RouteUrl.MARKETING_POSTER)">
                    <img slot="icon" src="~assets/x3/shop/Group@3x.png">
                    <span slot="label">转发海报</span>
                </grid-item>
                <grid-item @click.native="goUrl(RouteUrl.MARKETING_SOFT_PAPER)">
                    <img slot="icon" src="~assets/x3/shop/turn_soft3x.png">
                    <span slot="label">转发软文</span>
                </grid-item>
                <grid-item @click.native="goUrl(RouteUrl.SHOP_INDEX)">
                    <img slot="icon" src="~assets/x3/shop/shop_forward3x.png">
                    <span slot="label">转发店铺</span>
                </grid-item>
                <grid-item @click.native="goUrl(RouteUrl.SHOP_QRCODE)">
                    <img slot="icon" src="~assets/x3/shop/shop_qrcode.png">
                    <span slot="label">分享二维码</span>
                </grid-item> -->
                <!-- <grid-item @click.native="goUrl(RouteUrl.ACTIVITY_GREAT_BENEFIT)">
                    <img slot="icon" src="~assets/activity/icon-greatBenefit.png">
                    <span slot="label">新春大聚惠</span>
                </grid-item> -->
            </grid>
        </div>
        <div v-show="shopMenu['我的团队'].length!=0" class="shopManage-item shopManage-tool" v-if="isNotShareChannelUser">
            <group-title>
                <img width="20" class="manager-list" src="~assets/x3/ico/team.png">
                <div>我的团队</div>
            </group-title>
            <grid :cols="shopRows">
                <grid-item v-for="(menu,index) in shopMenu['我的团队']" :key="index" @click.native="goMenu(menu)">
                    <img slot="icon" :src="menu.imgUrl">
                    <span slot="label">{{menu.serviceCname}}</span>
                </grid-item>
                <!-- <grid-item @click.native="goUrl(RouteUrl.MY_FRIENDS)">
                    <img slot="icon" src="~assets/x3/channel/menu_ico/(1).png">
                    <span slot="label">查询好友</span>
                </grid-item>
                <grid-item @click.native="goUrl(RouteUrl.REGISTER_INVITE)">
                    <img slot="icon" src="~assets/x3/channel/menu_ico/(2).png">
                    <span slot="label">邀请好友</span>
                </grid-item> -->
            </grid>
        </div>
    </div>
</template>

<script>
import Menu from 'src/js/menu';
import onlineCustomerService from "src/js/onlineCustomerService";//引入在线客服js
import SharePage from "src/js/sharePage"; //引入微信分享js
import { RequestUrl } from "src/common/url";
// import { RouteUrl, Mutations, intervalTime, TypeInsurance, FooterShow, PopState } from "src/common/const";
import { mapState, mapActions } from "vuex";
import { FooterIndex, Mutations, SaveName, RouteUrl, WeChatShare, Url_Key, TO_TYPE } from "src/common/const";
import { XHeader, CheckerItem, Group, Scroller, Checker, Cell, XButton, Panel, Grid, GridItem, GroupTitle } from "vux";
import shopHeader from "src/components/shop/shopHeader";
export default {
    computed: mapState(["region", "user", "initUrl", "saveInsure", "isWeChar", "shop", "shareUuid", "isQueryHeader", "shopMenu", "isInitData", "shopRows"]),
    components: {
        shopHeader,
        Grid,
        GridItem,
        GroupTitle
    },
    data() {
        return {
            manager: [],
            tool: [],
            team: [],
            RouteUrl: {},
            listType: '0',
            isNotShareChannelUser: true,//是否分享注册的渠道账户，即 2 = 末及渠道
            isModifyShopInfo: true,//是否显示店铺设置菜单
        };
    },
    watch: {
        isQueryHeader(cur, old) {
            if (cur) {
                this.initShare();
            }
        },
        // isInitData(cur, old) {
        //     this.initMenu();
        // }
    },
    methods: {
        //是否显示该菜单
        isDisplay(menu) {
            if (menu.serviceCname != '店铺信息设置') {
                return true;
            } else {
                //registerType = 注册类型：0=wx自主/分享注册(个人用户)，1=后台注册(渠道用户)，2=分享注册(渠道用户)
                //canModify = 是否允许前端修改渠道信息,0:否,1:是

                //注册类型不为个人的才需要判断是否允许修改店铺信息（业务关系代码）
                if (this.$common.isNotEmpty(this.user.userDto.registerType)
                    && this.user.userDto.registerType != "0"
                    && this.$common.isNotEmpty(this.user.userDto.canModify)
                    && this.user.userDto.canModify == "0") {
                    return false;//不显示店铺设置菜单
                } else {
                    return true;//可以修改店铺信息
                }
            }
        },
        goMenu(menu) {
            let data = {
                _this: this,
                menu: menu
            }
            if (menu.toType == TO_TYPE.CUSTOMER) {
                // onlineCustomerService.onlineClickOfMobile(this, menu.serviceUrl);
                //触发在线客服的click事件，IOS系统在使用.native修饰符时，需要调用2次才能触发到click
                if (localStorage["BOTYPE"] == "I") {
                    $(".zhiCustomBtn").trigger("click");
                    $(".zhiCustomBtn").trigger("click");
                } else {
                    $(".zhiCustomBtn").trigger("click");
                    // $(".zhiCustomBtn").trigger("click");
                }
                return;
            }
            Menu.goMenu(data);
        },
        setListType() {
            if (this.shop.shopHeaderState.listType == '0') {
                this.listType = '1';
            } else {
                this.listType = '0';
            }
            this.$common.storeCommit(this, Mutations.LIST_TYPE, this.listType);
        },
        goUrl(type) {
            // let url = "";
            // if (type == "shopInfoSet") {
            //     url = RouteUrl.SHOP_INDEX;
            // }
            this.$common.goUrl(this, type);
        },
        initShare() {
            sessionStorage["SHARE_COMMON_TYPE"] = "USER";
            // refShareUUid
            let _this = this;
            let parmList = [];
            let uuid = "";
            // uuid = this.shareUuid;
            uuid = this.$encode.hex_md5(this.user.userDto.userCode + ":1");
            this.$common.storeCommit(this, Mutations.SET_SHARE_UUID, uuid);
            let urlParm = {
                key: Url_Key.SHARE_UUID,
                value: uuid
            }
            parmList.push(urlParm);
            let shareUrl = RequestUrl.BASE_URL + RouteUrl.SHOP_INDEX + this.$common.setShareUrl(parmList);
            this.shopShareUrl = shareUrl;
            let shopIntroduct = this.shop.shopHeaderState.shopIntroduct;
            if (this.$common.isEmpty(shopIntroduct)) {
                shopIntroduct = "利宝保险";
            }

            let imgUrl = this.shop.shopHeaderState.header;
            if (imgUrl.indexOf("http:") < 0 && imgUrl.indexOf("https:") < 0) {
                //补全产品的图片路径
                imgUrl = RequestUrl.WEB_PATH + imgUrl;
            }
            if (imgUrl == "") {
                imgUrl = RequestUrl.WEB_PATH + "sticsale/upload/assets/x3/logo.jpg"
            }

            // alert("shopUrl:" + shareUrl);
            let shareData = {
                _this: this,
                shareData: {
                    title: this.shop.shopHeaderState.shopName,
                    desc: shopIntroduct,
                    imgUrl: imgUrl,
                    url: shareUrl,
                    _this: this,
                    type: 3
                }
            };
            // document.title = this.shop.shopHeaderState.shopName;
            // share.shareInit(shareData);
            // debugger
            SharePage.weChatShare(shareData);

        },
        // initMenu() {
        //     //             manager:[],
        //     // tool:[],   销售工具
        //     // team:[],   我的团队
        //     if (this.isInitData) {
        //         if (typeof (this.shopMenu['店铺管理']) != "undefined") {
        //             this.manager = this.shopMenu['店铺管理'];
        //         }
        //         if (typeof (this.shopMenu['销售工具']) != "undefined") {
        //             this.tool = this.shopMenu['销售工具'];
        //         }
        //         if (typeof (this.shopMenu['我的团队']) != "undefined") {
        //             this.team = this.shopMenu['我的团队'];
        //         }
        //     }
        // }
    },
    beforeDestroy() {
        // if (this.isShopProManage) {
        let _this = this;
        let state = this.shop.shopHeaderState.isShowDetl + this.shop.shopHeaderState.isShowHot + this.shop.shopHeaderState.listType;
        // if (state != this.user.userDto.typeState) {
        if (state != this.shop.shopHeaderState.baseType) {
            let query = {
                stateType: state,
                userCode: this.user.userDto.userCode,
                TYPE: "FORM"
            }
            // this.$http.post(RequestUrl.SET_STATE_TYPE, query).then(function(res) {
            // });

            //本地token
            let localToken = localStorage[SaveName.JWT_TOKEN_NAME];
            $.ajax({
                type: "POST",
                url: RequestUrl.SET_STATE_TYPE,
                data: query,
                async: false,
                headers: {
                    "authorization": localToken,
                    // "Accept": "application/json; charset=utf-8",
                    // "Content-Type": "application/x-www-form-urlencoded",
                },
                success: function (res, status, xhr) {
                    _this.$common.reJwtVal(res);
                }
            });
        }
        // }
        // }
    },
    mounted() {
        document.title = "店铺管理";
        sessionStorage["INSURANCE_FORM_URL"] = RouteUrl.SHOP_MANAGE;
        sessionStorage["SHOP_INDEX_FORM_PATH"] = RouteUrl.SHOP_MANAGE;
        // if(this.user.isLogin&&this.user.userDto.){
        if (this.isQueryHeader) {
            this.initShare();
        }
        // }
        // alert("测试页面，请先绑定业务关系代码");
        let data = {
            _this: this,
            userCode: this.user.userDto.userCode,
            type: "",
            isMana: true,
            isShopIndex: false,

        }
        // alert(this.user.userDto.userCode);
        this.$common.storeCommit(this, Mutations.SET_SHOP_HEADER_STATE, data);

        this.$init.subPageInit(this);
        this.RouteUrl = RouteUrl;
        // this.initMenu();

        if (this.$common.isNotEmpty(this.user.userDto.registerType)) {
            if (this.user.userDto.registerType == "2") {
                this.isNotShareChannelUser = false;//末及渠道不显示我的团队菜单
            }
        }

        data = { product: "", user: "" };
        if (this.user.isLogin) {
            data.user = this.user.userDto;
        }
        //远程加载在线客服js
        onlineCustomerService.initJsFile(this, data);
    },
}
</script>

<style  lang="scss">
.manager-list {
  display: inline;
  margin-right: 5px;
  height: 16px;
  width: 16px;
  float: left;
  margin-top: 2px;
}
.shopManage-item {
  background: #fff;
  .weui-cells__title {
    margin-top: 0px;
    margin-bottom: 0px;
    padding-top: 7px;
    padding-bottom: 7px;
  }
  .weui-grids {
    .weui-grid {
      .weui-grid__label {
        color: #999999;
        font-size: 12px;
      }
    }
    .weui-grid:before {
      border-right: 1px solid #fff !important;
    }
  }
  .weui-cells__title {
    color: #000;
  }
}

.shopManage-tool {
  margin-top: 20px;
}
</style>
